package com.github.dongliusuo.sshtunneldemo;


public class SshTunnelProperties {

    /**
     * 远程服务器地址
     */
    private String sshHost;

    /**
     * ssh端口号
     */
    private Integer sshPort;

    /**
     * 用户名
     */
    private String sshUser;

    /**
     * 密码 注意密码和私钥同时有值时，密码字段就变为了私钥的passphrase
     */
    private String sshPassword;

    /**
     * 私钥路径 注意密码和私钥同时有值时，密码字段就变为了私钥的passphrase
     */
    private String privateKeyPath;

    /**
     * SSH 连接超时时间
     */
    private int sshConnectTimeout;

    /**
     * 本地机器上用于SSH隧道的端口号
     */
    private Integer localPort;

    /**
     * 远程主机的地址
     * 通常为localhost ,代表你要连接的服务和SSH服务器在同一个机器上，如果不在同一机器上，要配置远程服务的主机地址
     */
    private String remoteHost;

    /**
     * 远程主机上的端口号
     * 远程服务运行在哪个端口上
     */
    private Integer remotePort;

    public SshTunnelProperties() {
    }

    /**
     * 适用于ssh服务器和远程服务在同一台主机上的场景
     *
     * @param sshHost        主机地址
     * @param sshUser        主机端口
     * @param sshPassword    密码
     * @param privateKeyPath 私钥路径，注意密码和私钥同时有值时，密码字段就变为了私钥的passphrase
     * @param localPort      本地端口号
     * @param remotePort     服务的端口号
     */
    public SshTunnelProperties(String sshHost, String sshUser, String sshPassword, String privateKeyPath, Integer localPort, Integer remotePort) {
        this(sshHost, 22, sshUser, sshPassword, privateKeyPath, 0, localPort, "localhost", remotePort);
    }

    /**
     * 适用于ssh服务器和远程服务在同一台主机上的场景
     *
     * @param sshHost           主机地址
     * @param sshUser           主机端口
     * @param sshPassword       密码
     * @param privateKeyPath    私钥路径，注意密码和私钥同时有值时，密码字段就变为了私钥的passphrase
     * @param sshConnectTimeout SSH超时时间
     * @param localPort         本地端口号
     * @param remotePort        服务的端口号
     */
    public SshTunnelProperties(String sshHost, String sshUser, String sshPassword, String privateKeyPath, int sshConnectTimeout, Integer localPort, Integer remotePort) {
        this(sshHost, 22, sshUser, sshPassword, privateKeyPath, sshConnectTimeout, localPort, "localhost", remotePort);
    }

    /**
     * 适用于ssh服务器和远程服务不在同一台主机上的场景
     *
     * @param sshHost        主机地址
     * @param sshUser        主机端口
     * @param sshPassword    密码
     * @param privateKeyPath 私钥路径，注意密码和私钥同时有值时，密码字段就变为了私钥的passphrase
     * @param localPort      本地端口号
     * @param remoteHost     服务所在的主机
     * @param remotePort     服务的端口号
     */
    public SshTunnelProperties(String sshHost, String sshUser, String sshPassword, String privateKeyPath, Integer localPort, String remoteHost, Integer remotePort) {
        this(sshHost, 22, sshUser, sshPassword, privateKeyPath, 0, localPort, remoteHost, remotePort);
    }


    /**
     * 适用于ssh服务器和远程服务不在同一台主机上的场景
     *
     * @param sshHost           主机地址
     * @param sshUser           主机端口
     * @param sshPassword       密码
     * @param privateKeyPath    私钥路径，注意密码和私钥同时有值时，密码字段就变为了私钥的passphrase
     * @param sshConnectTimeout SSH超时时间
     * @param localPort         本地端口号
     * @param remoteHost        服务所在的主机
     * @param remotePort        服务的端口号
     */
    public SshTunnelProperties(String sshHost, String sshUser, String sshPassword, String privateKeyPath, int sshConnectTimeout, Integer localPort, String remoteHost, Integer remotePort) {
        this(sshHost, 22, sshUser, sshPassword, privateKeyPath, 0, localPort, remoteHost, remotePort);
    }

    /**
     * 全量的属性的构造器
     */
    public SshTunnelProperties(String sshHost, Integer sshPort, String sshUser, String sshPassword, String privateKeyPath, int sshConnectTimeout, Integer localPort, String remoteHost, Integer remotePort) {
        this.sshHost = sshHost;
        this.sshPort = sshPort;
        this.sshUser = sshUser;
        this.sshPassword = sshPassword;
        this.privateKeyPath = privateKeyPath;
        this.sshConnectTimeout = sshConnectTimeout;
        this.localPort = localPort;
        this.remoteHost = remoteHost;
        this.remotePort = remotePort;
    }

    @Override
    public String toString() {
        return "SshTunnelProperties{" +
                "sshHost='" + sshHost + '\'' +
                ", sshPort=" + sshPort +
                ", sshUser='" + sshUser + '\'' +
                ", sshPassword='" + sshPassword + '\'' +
                ", privateKeyPath='" + privateKeyPath + '\'' +
                ", sshConnectTimeout=" + sshConnectTimeout +
                ", localPort=" + localPort +
                ", remoteHost='" + remoteHost + '\'' +
                ", remotePort=" + remotePort +
                '}';
    }

    public String getSshHost() {
        return sshHost;
    }

    public void setSshHost(String sshHost) {
        this.sshHost = sshHost;
    }

    public Integer getSshPort() {
        return sshPort;
    }

    public void setSshPort(Integer sshPort) {
        this.sshPort = sshPort;
    }

    public String getSshUser() {
        return sshUser;
    }

    public void setSshUser(String sshUser) {
        this.sshUser = sshUser;
    }

    public String getSshPassword() {
        return sshPassword;
    }

    public void setSshPassword(String sshPassword) {
        this.sshPassword = sshPassword;
    }

    public String getPrivateKeyPath() {
        return privateKeyPath;
    }

    public void setPrivateKeyPath(String privateKeyPath) {
        this.privateKeyPath = privateKeyPath;
    }

    public int getSshConnectTimeout() {
        return sshConnectTimeout;
    }

    public void setSshConnectTimeout(int sshConnectTimeout) {
        this.sshConnectTimeout = sshConnectTimeout;
    }

    public Integer getLocalPort() {
        return localPort;
    }

    public void setLocalPort(Integer localPort) {
        this.localPort = localPort;
    }

    public String getRemoteHost() {
        return remoteHost;
    }

    public void setRemoteHost(String remoteHost) {
        this.remoteHost = remoteHost;
    }

    public Integer getRemotePort() {
        return remotePort;
    }

    public void setRemotePort(Integer remotePort) {
        this.remotePort = remotePort;
    }
}
